/**
 * File: ContigIndexController.java
 * Created by: mhaimel
 * Created on: Apr 20, 2010
 * CVS:  $Id: ContigIndexController.java 1.0 Apr 20, 2010 3:41:24 PM mhaimel Exp $
 */
package uk.ac.ebi.curtain.controller.loader;

import java.io.File;
import java.util.List;

import uk.ac.ebi.curtain.controller.ParallelSingleSubmitController;
import uk.ac.ebi.curtain.controller.SimpleReport;
import uk.ac.ebi.curtain.management.IControllerReport;
import uk.ac.ebi.curtain.processor.load.ContigIndexProcessor;
import uk.ac.ebi.curtain.utils.CurtainUncheckedException;
import uk.ac.ebi.curtain.utils.data.DataEntry;
import uk.ac.ebi.curtain.utils.data.FileType;
import uk.ac.ebi.curtain.utils.data.MetaData;
import uk.ac.ebi.curtain.utils.data.ReadType;
import uk.ac.ebi.curtain.utils.data.impl.GenericDataHolder;
import uk.ac.ebi.curtain.utils.file.FileInfo;

/**
 * @author mhaimel
 *
 */
public class ContigIndexController extends ParallelSingleSubmitController<DataEntry<File>, DataEntry<File>, ContigIndexProcessor>{

	@Override
	protected void singleSubmit(List<DataEntry<File>> inputList) {
		
		List<FileInfo> files = getContext().getArguments().getFiles(ReadType.Contig, FileType.values());
		if(files.size() > 1){
			throw new CurtainUncheckedException("Only one Contig file allowed!!!");
		}
		if(files.isEmpty()){
			throw new CurtainUncheckedException("One Contig input file required!!!");
		}
		
		for(FileInfo fi : files){
			ContigIndexProcessor instance = getContext().getInjector().getInstance(ContigIndexProcessor.class);
			instance.setInput(new GenericDataHolder<File>(new MetaData(-1, fi.getFileType(), fi.getReadType()), fi.getFile()));
			submit(instance);
		}
	}
	
	@Override
	protected IControllerReport getReturnCall() {
		return new SimpleReport("Finished");
	}

	
}
